package com.baizhi.springboot.service.impl;

import com.baizhi.springboot.dao.CarDao;
import com.baizhi.springboot.entity.*;
import com.baizhi.springboot.service.CarService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Service
public class CarServiceImpl implements CarService {
    @Autowired
    private CarDao carDao;
    @Override
    public Map selectCarByPage(Integer page, Integer limit) {
        Integer offset=(page-1)*limit;
        List<Car> cars = carDao.selectCarByPage(offset, limit);
        Integer count = carDao.selectCount();
        /* "code": 0,
          "msg": "",
          "count": 1000,
          "data": [{}, {}]*/
        HashMap<Object, Object> map = new HashMap<>();
        map.put("code", 0);
        map.put("msg", "");
        map.put("count", count);
        map.put("data", cars);
        return map;
    }

    @Override
    public void insertCar(Car car) {
        carDao.insertCar(car);
    }

    @Override
    public void deleteCar(Integer id) {
        carDao.deleteCar(id);
    }

    @Override
    public Car selectOneCar(Integer id) {
        return carDao.selectOneCar(id);
    }

    @Override
    public void updateCar(Car car) {
        carDao.updateCar(car);
    }

    @Override
    public void insertCarApplyFor(CarApplyFor carApplyFor) {
        carDao.insertCarApplyFor(carApplyFor);
    }

    @Override
    public void insertSeal(Seal seal) {
        carDao.insertSeal(seal);
    }

    @Override
    public void insertBook(Book book) {
        carDao.insertBook(book);
    }

    @Override
    public void insertCard(Card card) {
        carDao.insertCard(card);
    }
}
